package com.lzy.imagepickerdemo.imageloader;

import android.app.Activity;
import android.net.Uri;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

import com.bumptech.glide.request.RequestOptions;
import com.lzy.imagepickerdemo.R;
import com.zxn.imagepicker.loader.ImageLoader;

import java.io.File;

/**
 * Created by zxn on 2019/5/17.
 * https://github.com/jeasonlzy0216
 */
public class GlideImageLoader implements ImageLoader {

    @Override
    public void displayImage(Activity activity, String path, ImageView imageView, int width, int height) {

        Glide.with(activity)                             //配置上下文
                .load(Uri.fromFile(new File(path)))      //设置图片路径(fix #8,文件名包含%符号 无法识别和显示)
                .into(imageView);
        /*.apply(RequestOptions
                //.errorOf(R.drawable.ic_default_image)//设置错误图片
                //.placeholder(R.drawable.ic_default_image)//设置占位图片
                .diskCacheStrategy(DiskCacheStrategy.ALL)//缓存全尺寸
        )*/
    }

    @Override
    public void displayImagePreview(Activity activity, String path, ImageView imageView, int width, int height) {
        Glide.with(activity)                             //配置上下文
                .load(Uri.fromFile(new File(path)))      //设置图片路径(fix #8,文件名包含%符号 无法识别和显示)
                .apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL))//缓存全尺寸
                .into(imageView);
    }

    @Override
    public void clearMemoryCache() {

    }
}
